﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SiGeMEC.Models;

namespace SiGeMEC.Controllers
{
  public class TareaController : Controller
  {
    private SigemecContext db = new SigemecContext();

    //
    // GET: /Tarea/

    public ViewResult Index()
    {
      return View(db.Tareas.ToList());
    }

    //
    // GET: /Tarea/Details/5

    public ViewResult Details(int id)
    {
      Tarea tarea = db.Tareas.Find(id);
      return View(tarea);
    }

    //
    // GET: /Tarea/Create

    public ActionResult Create()
    {
      return View();
    }

    //
    // POST: /Tarea/Create

    [HttpPost]
    public ActionResult Create(Tarea tarea)
    {
      if (ModelState.IsValid)
      {
        db.Tareas.Add(tarea);
        db.SaveChanges();
        return RedirectToAction("Index");
      }

      return View(tarea);
    }

    //
    // GET: /Tarea/Edit/5

    public ActionResult Edit(int id)
    {
      Tarea tarea = db.Tareas.Find(id);
      return View(tarea);
    }

    //
    // POST: /Tarea/Edit/5

    [HttpPost]
    public ActionResult Edit(Tarea tarea)
    {
      if (ModelState.IsValid)
      {
        db.Entry(tarea).State = EntityState.Modified;
        db.SaveChanges();
        return RedirectToAction("Index");
      }
      return View(tarea);
    }

    //
    // GET: /Tarea/Delete/5

    public ActionResult Delete(int id)
    {
      Tarea tarea = db.Tareas.Find(id);
      return View(tarea);
    }

    //
    // POST: /Tarea/Delete/5

    [HttpPost, ActionName("Delete")]
    public ActionResult DeleteConfirmed(int id)
    {
      Tarea tarea = db.Tareas.Find(id);
      db.Tareas.Remove(tarea);
      db.SaveChanges();
      return RedirectToAction("Index");
    }

    protected override void Dispose(bool disposing)
    {
      db.Dispose();
      base.Dispose(disposing);
    }
  }
}